//
//  WQCBankViewController.m
//  renxinghuan
//
//  Created by 王晓民 on 2018/3/30.
//  Copyright © 2018年 吴清翠. All rights reserved.
//

#import "WQCBankViewController.h"
#import "configuration.h"
#import "UIButton+CountDown.h"
#import "WYCZhifusetController.h"
#import "WQCSetPassController.h"
@interface WQCBankViewController ()<UITableViewDelegate,UITableViewDataSource>
@property(nonatomic,strong)UITableView  *bankTable;
@property(nonatomic,strong)UITextField * UserTextField;


@end

@implementation WQCBankViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = WYCGlobalBg;
    self.navigationItem.title = @"设置密码";
    [self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor whiteColor]}];
    [self.navigationController.navigationBar setBarTintColor:wycMain];
    
    UILabel  *jiesuan = [MyUIClass makeUILabelWithFrame:CGRectMake(10, NavHeight+20, ScreenWidth-20, 20) andBackColor:[UIColor clearColor] andText:@"任性还将发送6位数字短信验证码到你的手机" andTextColor:[UIColor lightGrayColor] andFont:[UIFont systemFontOfSize:13] andAlignment:NSTextAlignmentLeft];
    
    [self.view addSubview:jiesuan];
    
    if (@available(iOS 11.0, *)) {
        self.bankTable.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
    } else {
        self.automaticallyAdjustsScrollViewInsets = NO;
    }
    
    self.bankTable = [[UITableView alloc] initWithFrame:CGRectMake(0, kDevice_Is_iPhoneX ? 88+40:64+40, ScreenWidth, WYCcellHeight * 3 + 50 * px) style:UITableViewStylePlain];
    self.bankTable.backgroundColor = WYCGlobalBg;
    self.bankTable.dataSource = self;
    self.bankTable.scrollEnabled = NO;
    self.bankTable.delegate = self;
    [self.view addSubview:self.bankTable];
    //注册按钮
    UIButton * loginButton = [[UIButton alloc] init];
    loginButton.frame = CGRectMake(40 * px, 350, ScreenWidth - 80 * px, 150 * px);
    loginButton.backgroundColor = wycMain;
    loginButton.layer.cornerRadius = 3;
    [loginButton setTitle:@"提交" forState:UIControlStateNormal];
    loginButton.titleLabel.font = [UIFont systemFontOfSize:72 * px];
    [loginButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [loginButton addTarget:self action:@selector(loadChek) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:loginButton];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    return 1;
}


- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    
    return WYCcellHeight;
    
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    
    tableView.tableFooterView = [[UIView alloc] init];
    UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"123"];
    if (!cell) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"123"];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    UITextField * codeTextField = [[UITextField alloc] init];
    codeTextField.frame = CGRectMake( 30 * px,10,  200, 20);
    codeTextField.backgroundColor = [UIColor clearColor];
    codeTextField.placeholder = @"请输入验证码";
    codeTextField.keyboardType = UIKeyboardTypeNumberPad;
    codeTextField.tintColor = wycMain;
    [cell.contentView addSubview:codeTextField];
    self.UserTextField=codeTextField;
    
    UIButton * forgetButton = [[UIButton alloc] init];
    forgetButton.frame = CGRectMake(ScreenWidth-125, 8, 120, 30);
    forgetButton.titleLabel.font = [UIFont systemFontOfSize:WyzFont];
    forgetButton.backgroundColor = wycMain;
    forgetButton.layer.cornerRadius = 15;
    [forgetButton setTitle:@"获取验证码" forState:UIControlStateNormal];
    [forgetButton addTarget:self action:@selector(countDownBtnAction:) forControlEvents:UIControlEventTouchUpInside];
    [forgetButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [cell.contentView addSubview:forgetButton];
    //密码
    return cell;
}
#pragma make ------>>获取验证码
- (void)countDownBtnAction:(UIButton *)button
{
    [SVProgressHUD setDefaultStyle:SVProgressHUDStyleCustom];
    [SVProgressHUD setForegroundColor:[UIColor whiteColor]]; //字体颜色
    [SVProgressHUD setBackgroundColor:[UIColor blackColor]];   //背景颜色
        
        [button startWithTime:59 title:@"点击重新获取" countDownTitle:@"s后重新获取" mainColor:wycMain countColor: [UIColor lightGrayColor]];
        
        NSMutableDictionary * params = [NSMutableDictionary dictionary];
        params[@"mobile"] = [WYCAccountTool unarchivemobile];
    
    if ([self.myFlag isEqualToString:@"888"]) {
        params[@"type"] = @"upwd";
    }
    else{
        params[@"type"] = @"uppwd";
    }
        NSLog(@"%@",params);
        [HttpTool POST:Rcode params:params success:^(NSURLSessionDataTask *task, id responseObject) {
            
            if ([[responseObject objectForKey:@"code"] intValue] == 0) {
             
                [SVProgressHUD showImage:[UIImage imageNamed:@""] status:msgStr];

            }else{
                
                [SVProgressHUD showImage:[UIImage imageNamed:@""] status:msgStr];
                
            }
            
        } fail:^(NSURLSessionDataTask *task, NSError *error) {
            
        }];
        
    
}

-(void)loadChek{
    if (self.UserTextField.text.length==0) {
        [SVProgressHUD showImage:nil status:@"验证码不能为空"];
        return;
    }else
    {
    NSMutableDictionary * params = [NSMutableDictionary dictionary];
    
    params[@"mobile"] =[WYCAccountTool unarchivemobile];
    params[@"code"] =self.UserTextField.text;
    
    NSLog(@"%@",params);
    [HttpTool POST:checkPhone params:params success:^(NSURLSessionDataTask *task, id responseObject) {
        NSLog(@"验证%@",responseObject);
        if ([[responseObject objectForKey:@"code"] intValue] == 0) {
          
            if ([self.myFlag isEqualToString:@"888"]) {
                WQCSetPassController  *zhifu = [[WQCSetPassController alloc]init];
                zhifu.codeStr =self.UserTextField.text;
                [self.navigationController pushViewController:zhifu animated:YES];
            }
            else{
                WYCZhifusetController  *zhifu = [[WYCZhifusetController alloc]init];
                zhifu.codeStr =self.UserTextField.text;
                [self.navigationController pushViewController:zhifu animated:YES];
            }
        }
        else
        {
            [SVProgressHUD showImage:nil status:@"验证码输入错误"];

        }
        
    } fail:^(NSURLSessionDataTask *task, NSError *error) {
        [SVProgressHUD showImage:nil status:Failed];
        
    }];
    }
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
